/**
 * 
 */
package com.depot.org.organization.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.base.LoginUser;
import com.depot.DepotConstants;
import com.depot.domains.Organization;
import com.depot.org.organization.dao.OrganizationDao;
import com.opensymphony.xwork2.ModelDriven;
import com.soar.BaseActionSupport;
import com.soar.context.Environment;

public class OrganizationAction extends BaseActionSupport implements ModelDriven<Organization>
{
	private static final long serialVersionUID = 1L;

	public Organization domain = new Organization();

	public HashMap<String, String> organization = new HashMap<String, String>();
	
	public List<HashMap<String, String>> managerlist = new ArrayList<HashMap<String,String>>();

	
	/**
	 * 组织机构_list
	 * 
	 * @param env
	 * @param domain
	 * @param action
	 * @return
	 * @throws Exception
	 */
	public String execute(Environment env) throws Exception
	{
		String rolecode=env.getLoginUser(LoginUser.class).getUserRoleCode();
		if( DepotConstants.ORG_ORDINARY_CODE.equals(rolecode)){
			this.organization=OrganizationDao.select(env, domain, null,rolecode).get(0);
			return "manager_org_list";
		}
		else {
			this.sysPageList = OrganizationDao.select(env, domain, this,rolecode);
			return "org_list";
		}
		
		
	}

	public String doShow(Environment env) throws Exception
	{
		this.organization = OrganizationDao.doShow(env, domain);
		return this.doNew(env);
	}

	public String doSave(Environment env) throws Exception
	{
		String result = OrganizationDao.doSave(env, domain);
		if (result.equals("1"))
		{
			this.setMessage("操作处理成功！", env, true);
		}
		else if (result.equals("0"))
		{
			this.setMessage("操作处理失败，请重试！", env, false);
		}
		else if (result.equals("2"))
		{
			this.setMessage("组织名称，组织代码已被使用，请换一个", env, false);
		}
		return this.execute(env);
	}
	/**
	 * 组织机构_delete
	 * 
	 * @param env
	 * @param domain
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	public String doDelete(Environment env) throws Exception
	{
		String result = OrganizationDao.doDelete(env, domain);
		return this.execute(env);
	}

	/**
	 * 组织机构_new
	 * 
	 * @param env
	 * @param domain
	 * @return
	 * @throws Exception
	 */
	public String doNew(Environment env) throws Exception
	{
		return "org_edit";
	}

	public Organization getModel()
	{
		return this.domain;
	}
}